<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>


    <title>在线信息</title>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/css/plugins/iCheck/custom.css}" rel="stylesheet"/>
    <link th:href="@{/css/plugins/summernote/summernote.css}" rel="stylesheet"/>
    <link th:href="@{/css/plugins/summernote/summernote-bs3.css}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-3">
            <div class="ibox float-e-margins">
                <div class="ibox-content mailbox-content">
                    <div class="file-manager">
                        <a class="btn btn-block btn-primary compose-mail" href="/message/toSendPage">发送留言</a>
                        <div class="space-25"></div>
                        <h5>文件夹</h5>
                        <ul class="folder-list m-b-md" style="padding: 0">
                            <li>
                                <a href="/message/toMessagePage/1?status=-3"> <i class="fa fa-inbox "></i> 留言箱 <span
                                        class="label label-warning pull-right" th:if="${unreads != null}"
                                        th:text="${unreads}">16</span>
                                </a>
                            </li>
                            <li>
                                <a href="/message/toMessagePage/1?status=-1"> <i class="fa fa-file-text-o"></i> 草稿 <span
                                        class="label label-info pull-right" th:if="${draft != null}" th:text="${draft}">1</span>
                                </a>
                            </li>
                            <li>
                                <a href="/message/toMessagePage/1?status=-2"> <i class="fa fa-trash-o"></i> 垃圾箱<span
                                        class="label label-danger pull-right" th:if="${garbage != null}"
                                        th:text="${garbage}">2</span></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-9 animated fadeInRight">
            <div class="mail-box-header">
                <div class="pull-right tooltip-demo">
                    <a href="#" class="btn btn-white btn-sm draft" data-toggle="tooltip" data-placement="top"
                       title="存为草稿" ><i class="fa fa-pencil"></i> 更新草稿</a>
                    <a href="#" class="btn btn-danger btn-sm delButton" data-toggle="tooltip" data-placement="top"
                       title="放弃" onclick="discard()"><i class="fa fa-times"></i> 放弃</a>
                </div>
                <h2>
                    写信
                </h2>
            </div>
            <div class="mail-box">


                <div class="mail-body">

                    <form class="form-horizontal" method="get">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">发送到：</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="email" th:value="${message.msgReceiverEmail}" onblur="checkEmail()"
                                />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">主题：</label>

                            <div class="col-sm-10">
                                <input type="text" id="title" th:value="${message.msgTitle}" class="form-control" value=""/>
                            </div>
                        </div>
                    </form>

                </div>

                <div class="mail-text h-200">

                    <div class="summernote">

                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="mail-body text-right tooltip-demo">
                    <a href="#" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="top"
                       title="Send" id="sendButton"><i class="fa fa-reply"></i> 发送</a>
                    <a href="#" class="btn btn-white btn-sm delButton" data-toggle="tooltip" data-placement="top"
                       title="Discard email"><i class="fa fa-times"></i> 放弃</a>
                    <a href="#" class="btn btn-white btn-sm draft" data-toggle="tooltip" data-placement="top"
                       title="Move to draft folder"><i class="fa fa-pencil"></i> 更新草稿</a>
                </div>
                <div class="clearfix"></div>


            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>


<!-- 自定义js -->
<script th:src="@{/js/content.js}"></script>


<!-- iCheck -->
<script th:src="@{/js/plugins/iCheck/icheck.min.js}"></script>

<!-- SUMMERNOTE -->
<script th:src="@{/js/plugins/summernote/summernote.min.js}"></script>
<script th:src="@{/js/plugins/summernote/summernote-zh-CN.js}"></script>
<script th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script th:inline="javascript">
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });


        $('.summernote').summernote({
            lang: 'zh-CN',
            height: 200
        });
        $('.summernote').code([[${message.msgContent}]]);

        $(".delButton").on("click",function () {
            $.ajax({
                url: "/message/remove",
                type: "post",
                data: {
                    msgId: [[${message.msgId}]]
                },
                success: function (data) {
                    if (data.code == 200) {
                        location.href = "/message/toMessagePage/1?status=-1";
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        });

        $("#sendButton").click(function () {
            var content = $('.summernote').code();
            var title = $("#title").val();
            var receiver = $("#email").val();
            $.ajax({
                url: "/message/updateDraft",
                type: "post",
                data: {
                    msgId:[[${message.msgId}]],
                    msgReceiverEmail: receiver,
                    msgContent: content,
                    msgTitle: title,
                    msgStatus: -3
                },
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg("发送成功");
                        setTimeout(function () {
                            // parent.location.reload();
                            history.back(-1);
                            location.reload();
                            // location.reload();
                            // var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            // parent.layer.close(index);
                        }, 1000);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        });

        $(".draft").click(function () {
            var content = $('.summernote').code();
            var title = $("#title").val();
            var receiver = $("#email").val();
            $.ajax({
                url: "/message/updateDraft",
                type: "post",
                data: {
                    msgId:[[${message.msgId}]],
                    msgSenderEmail:[[${message.msgSenderEmail}]],
                    msgReaded:0,
                    msgReceiverEmail: receiver,
                    msgContent: content,
                    msgTitle: title,
                    msgStatus: -1
                },
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg("更新草稿成功");
                        setTimeout(function () {
                            // parent.location.reload();
                            // history.back(-1);
                            location.reload();
                            // location.reload();
                            // var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            // parent.layer.close(index);
                        }, 1000);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        });
    });


    function discard() {
        location.reload();
    }

    var edit = function () {
        $('.click2edit').summernote({
            focus: true
        });
    };
    var save = function () {
        var aHTML = $('.click2edit').code(); //save HTML If you need(aHTML: array).
        $('.click2edit').destroy();
    };

    function checkEmail() {
        var email = $("#email").val();
        $.ajax({
            url: "/message/checkEmail",
            type: "post",
            data: {
                email: email
            },
            success: function (data) {
                if (data.code != 200) {
                    layer.msg(data.msg);
                }
            }
        });
    }
</script>

<!--<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>-->
<!--&lt;!&ndash;统计代码，可删除&ndash;&gt;-->

</body>

</html>
